package com.zhouzhou.fastjava.query.dialect;

import com.zhouzhou.fastjava.query.ColumnMapping;
import com.zhouzhou.fastjava.query.ModuleQueryStatement;
import com.zhouzhou.fastjava.query.QueryArgs;
import com.zhouzhou.fastjava.query.QuerySortor;

import java.util.List;

/**
 * User: liuzheqiang
 * Date: 2017/12/28
 * Time: 17:31
 */
public class SqlServerDialect extends Dialect {

    @Override
    public String getQueryListSQL(String module, ColumnMapping columnMapping, String sql, ModuleQueryStatement mqStatement, QueryArgs args, List<QuerySortor> sortors) {
        String orderSql = getOrderSql(module, columnMapping, mqStatement, sortors);
        int start = args.getStart();
        int limit = args.getLimit();

        return "select * from ( select top " + (start + limit) + " row_number() over(" + orderSql + ") rn, * from ( " + sql + " ) r) s where rn > " + start;
    }

}
